package com.wcgksoft.controller.admin;

import com.wcgksoft.common.util.Layui;
import com.wcgksoft.entity.admin.Account;
import com.wcgksoft.entity.system.SysUser;
import com.wcgksoft.service.admin.AccountService;
import com.wcgksoft.service.system.UserService;
import javafx.scene.chart.ValueAxis;
import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author 御风
 * @version V1.0
 * @Package com.wcgksoft.controller.admin
 * @Description TODO 验证表单提交的重复性
 * @date 2020/5/22 13:45
 * @ClassName ValidateController
 */
@Controller
@RequestMapping("validate")
public class ValidateController {

    @Autowired
    private AccountService accountService;

    @Autowired
    private UserService userService;

    @ResponseBody
    @RequestMapping(value = "validateForm")
    public Layui validateForm(@RequestParam(value = "phone",required = false)String phone){
        DetachedCriteria criteria = DetachedCriteria.forClass(SysUser.class);
        if (StringUtils.isNotEmpty(phone)){
            criteria.add(Restrictions.eq("phone",phone));
        }
        List<SysUser> list = userService.findByConditions(criteria);
        return Layui.data(0, "success",  list);
    }

    @ResponseBody
    @RequestMapping(value = "validateIdCard")
    public Layui validateIdCard(@RequestParam(value = "idCard",required = false)String idCard){
        DetachedCriteria criteria = DetachedCriteria.forClass(SysUser.class);
        if (StringUtils.isNotEmpty(idCard)){
            criteria.add(Restrictions.eq("idCard",idCard));
        }
        List<SysUser> list = userService.findByConditions(criteria);
        return Layui.data(0, "success",  list);
    }

    @ResponseBody
    @RequestMapping(value = "validateMobile")
    public Layui validateMobile(@RequestParam(value = "mobile",required = false)String mobile){
        DetachedCriteria criteria = DetachedCriteria.forClass(SysUser.class);
        if (StringUtils.isNotEmpty(mobile)){
            criteria.add(Restrictions.eq("mobile",mobile));
        }
        List<SysUser> list = userService.findByConditions(criteria);
        return Layui.data(0, "success",  list);
    }

    @ResponseBody
    @RequestMapping(value = "validateBankNum")
    public Layui validateBankNum(@RequestParam(value = "bankNum",required = false)String bankNum){
        DetachedCriteria criteria = DetachedCriteria.forClass(SysUser.class);
        if (StringUtils.isNotEmpty(bankNum)){
            criteria.add(Restrictions.eq("bankNum",bankNum));
        }
        List<SysUser> list = userService.findByConditions(criteria);
        return Layui.data(0, "success",  list);
    }


}
